#include "com.h"

int main()
{
  umask(0);
  if(mkfifo(FILE_NAME, 0644) < 0){
    perror("mkfifo");
    exit(1);
  } 

  int fd = open(FILE_NAME, O_WRONLY);
  if(fd < 0){
    perror("open");
    exit(2);
  }

  int infd = open("file.txt", O_RDONLY);
  
  char msg[128];
  while(1){
    ssize_t s = read(infd, msg, sizeof(msg));
    if(s == sizeof(msg)){
      write(fd, msg, s);  
    }
    else if(s < sizeof(msg)){
      write(fd, msg, s);
      printf("read file end\n");
      break;
    }
    else {
      perror("read");
      break;
    }
  }

  close(infd);
  close(fd);
  return 0;
}
